package com.lwj.service.impl;

import com.lwj.dao.TeamMapper;
import com.lwj.dao.UserMapper;
import com.lwj.dao.UserTeamMapper;
import com.lwj.entity.Team;
import com.lwj.entity.UserTeam;
import com.lwj.model.TeamMemberRes;
import com.lwj.service.TeamStatusService;
import com.lwj.util.DataRet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author linwj
 * @date 2018/5/11 15:20
 */
@Service
@Transactional
public class TeamStatusServiceImpl implements TeamStatusService {

    @Autowired
    private UserTeamMapper userTeamMapper;

    @Autowired
    private TeamMapper teamMapper;

    @Override
    public DataRet<String> ensureTeam(int userId,int teamId) {
        UserTeam userTeam=new UserTeam();
        userTeam.setUserId(userId);
        userTeam.setTeamId(teamId);
        userTeam= userTeamMapper.getByUserTeam(userTeam);
        userTeam.setRole(2);
        userTeamMapper.updateByPrimaryKey(userTeam);

        List<TeamMemberRes>teamMemberRes=userTeamMapper.getTeamMemberInfo(teamId);
        for (TeamMemberRes t:teamMemberRes
             ) {if (t.getRole()==1||t.getRole()==2){

        }else {
                 return new DataRet<>("确认成功");
        }

        }
        Team team=new Team();
        team=teamMapper.selectByPrimaryKey(teamId);
        team.setStatus("1");
        teamMapper.updateByPrimaryKey(team);
        return new DataRet<>("确认成功");
    }
}
